from selenium.webdriver.common.by import By

from common.utils import chromeDriver


class PersonalSetting:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/setting"
        self.driver = chromeDriver.driver
        self.driver.get(self.url)

    #页面元素检查
    def PersonalSettingsCheckElement(self):
        #检查页面标题
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.title___3cGwa")
        #检查姓名标签
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.baseView___3sRG3 > div.left___GavW0 > form > div:nth-child(2) > div > div.ant-col.ant-form-item-label > label")
        #检查姓名输入框
        self.driver.find_element(By.CSS_SELECTOR, "#name")
        #检查手机号标签
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.baseView___3sRG3 > div.left___GavW0 > form > div:nth-child(3) > div > div.ant-col.ant-form-item-label > label")
        #检查手机号输入框
        self.driver.find_element(By.CSS_SELECTOR, "#phone")
        #检查邮箱标签
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.baseView___3sRG3 > div.left___GavW0 > form > div:nth-child(4) > div > div.ant-col.ant-form-item-label > label")
        #检查邮箱输入框
        self.driver.find_element(By.CSS_SELECTOR, "#email")
        #检查个人介绍标签
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.baseView___3sRG3 > div.left___GavW0 > form > div:nth-child(5) > div > div.ant-col.ant-form-item-label > label")
        #检查个人介绍输入框
        self.driver.find_element(By.CSS_SELECTOR, "#profile")
        #检索提交按钮
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.baseView___3sRG3 > div.left___GavW0 > form > div.ant-space.ant-space-horizontal.ant-space-align-center > div:nth-child(2) > button")
        #添加屏幕截图
        chromeDriver.getScreenShot()

    def UpdateInformation(self, name, phone, email, profile):
        #清空输入框
        chromeDriver.clear(self.driver.find_element(By.CSS_SELECTOR, "#name"))
        chromeDriver.clear(self.driver.find_element(By.CSS_SELECTOR, "#phone"))
        chromeDriver.clear(self.driver.find_element(By.CSS_SELECTOR, "#email"))
        chromeDriver.clear(self.driver.find_element(By.CSS_SELECTOR, "#profile"))

        #输入姓名
        self.driver.find_element(By.CSS_SELECTOR, "#name").send_keys(name)
        #输入手机号
        self.driver.find_element(By.CSS_SELECTOR, "#phone").send_keys(phone)
        #输入邮箱
        self.driver.find_element(By.CSS_SELECTOR, "#email").send_keys(email)
        #输入个人简介
        self.driver.find_element(By.CSS_SELECTOR, "#profile").send_keys(profile)
        #添加屏幕截图
        chromeDriver.getScreenShot()

    def UpdatedInformationSuccessfully(self):
        #输入正确的信息
        self.UpdateInformation("209779", "123456", "123456", "offer")
        #点击提交按钮
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.baseView___3sRG3 > div.left___GavW0 > form > div.ant-space.ant-space-horizontal.ant-space-align-center > div:nth-child(2) > button").click()
        #添加屏幕截图
        chromeDriver.getScreenShot()


    def FailedToUpdateInformation(self):
        #1.不输入姓名，其他信息正常输入
        self.UpdateInformation("", "123456", "123456", "offer")
        #点击提交按钮
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.baseView___3sRG3 > div.left___GavW0 > form > div.ant-space.ant-space-horizontal.ant-space-align-center > div:nth-child(2) > button").click()
        #添加屏幕截图
        chromeDriver.getScreenShot()
        text = self.driver.find_element(By.CSS_SELECTOR, "#name_help > div").text
        assert text == "请输入您的昵称！"

        #2.不输入手机号，其他信息正常输入
        self.UpdateInformation("209779", "", "123456", "offer")
        #点击提交按钮
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.baseView___3sRG3 > div.left___GavW0 > form > div.ant-space.ant-space-horizontal.ant-space-align-center > div:nth-child(2) > button").click()
        #添加屏幕截图
        chromeDriver.getScreenShot()
        text = self.driver.find_element(By.CSS_SELECTOR, "#phone_help > div").text
        assert text == "请输入您的联系电话！"


        #3.不输入邮箱，其他信息正常输入
        self.UpdateInformation("209779", "123456", "", "offer")
        #点击提交按钮
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.baseView___3sRG3 > div.left___GavW0 > form > div.ant-space.ant-space-horizontal.ant-space-align-center > div:nth-child(2) > button").click()
        #添加屏幕截图
        chromeDriver.getScreenShot()
        text = self.driver.find_element(By.CSS_SELECTOR, "#email_help > div").text
        assert text == "请输入您的邮箱!"

        #4.不输入个人介绍，其他信息正常输入
        self.UpdateInformation("", "123456", "123456", "")
        #点击提交按钮
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div > div > div.right___2jdGg > div.baseView___3sRG3 > div.left___GavW0 > form > div.ant-space.ant-space-horizontal.ant-space-align-center > div:nth-child(2) > button").click()
        #添加屏幕截图
        chromeDriver.getScreenShot()
        text = self.driver.find_element(By.CSS_SELECTOR, "#profile_help > div").text
        assert text == "请输入个人简介!"
